package cn.ac.jaas.isc.vegetable.common.security.component;

import cn.ac.jaas.isc.vegetable.common.core.constant.CommonConstants;
import cn.ac.jaas.isc.vegetable.common.security.exception.VegetableAuth2Exception;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import lombok.SneakyThrows;

/**
 * @author 张高昌
 * @date 2022/4/23 10:06
 * @description: 功能描述
 */
public class VegetableAuth2ExceptionSerializer extends StdSerializer<VegetableAuth2Exception> {

    public VegetableAuth2ExceptionSerializer() {
        super(VegetableAuth2Exception.class);
    }

    @Override
    @SneakyThrows
    public void serialize(VegetableAuth2Exception value, JsonGenerator gen, SerializerProvider provider) {
        gen.writeStartObject();
        gen.writeObjectField("code", CommonConstants.FAIL);
        gen.writeStringField("msg", value.getMessage());
        gen.writeStringField("data", value.getErrorCode());
        gen.writeEndObject();
    }

}
